import os
import sys
import subprocess
import shutil

def run_build():
    # Create 'build' directory if it doesn't exist
    if not os.path.exists('build'):
        os.makedirs('build')

    # Change to 'build' directory
    os.chdir('build')

    # Run 'cmake ..'
    subprocess.run(['cmake', '..'])
    
    # Run 'make'.
    subprocess.run(['make'])

def remove_build():
    if os.path.exists('build'):
        shutil.rmtree('build')

if __name__ == "__main__":
    if len(sys.argv) < 2:
        print("Usage: python build.py [run | rm]")
        sys.exit(1)

    if sys.argv[1] == "run":
        run_build()
    elif sys.argv[1] == "rm":
        remove_build()
    else:
        print("Usage: python build.py [run | rm]")
        sys.exit(1)